import 'package:flutter/material.dart';
import 'package:flutter_ijkplayer/flutter_ijkplayer.dart';

class HomePage extends StatefulWidget {
  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  IjkMediaController controller = IjkMediaController();

  @override
  void initState() {
    controller.setNetworkDataSource('http://pan.fmtol.com:8096/Videos/25581/stream.mkv?api_key=563ae78924204fd5969d33e75e74ffeb', autoPlay: true);
    super.initState();
  }

  @override
  void dispose() {
    controller.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('刺猬索尼克'),
      ),
      body: Container(
        // width: MediaQuery.of(context).size.width,
        // height: 400,
        child: ListView(children: <Widget>[
          buildIjkPlayer(),
        ]),
      ),
    );
  }

  Widget buildIjkPlayer() {
    return Container(
      height: 300, // 这里随意
      child: IjkPlayer(
        mediaController: controller,
        controllerWidgetBuilder: (controller) {
          return DefaultIJKControllerWidget(
            controller: controller,
            doubleTapPlay: true,
            verticalGesture: true,
            horizontalGesture: true,
          );
        },
      ),
    );
  }
}
